package com.example.vv.service;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import java.io.Serializable;
import java.util.Date;
import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Data
public class Message {
    @JacksonXmlProperty(localName = "ToUserName")
    private String toUserName;

    @JacksonXmlProperty(localName = "FromUserName")
    private String fromUserName;

    @JacksonXmlProperty(localName = "CreateTime")
    private Date createTime;

    @JacksonXmlProperty(localName = "MsgType")
    private String msgType;

    @JacksonXmlProperty(localName = "Event")
    private String event;

    @JacksonXmlProperty(localName = "ChatId")
    private String chatId;

    @JacksonXmlProperty(localName = "ChangeType")
    private ChangeType changeType;

    @Getter
    @RequiredArgsConstructor
    public enum ChangeType implements Serializable {
        CREATE("create"),
        UPDATE("update"),
        DISMISS("dismiss"),
        ;

        private final String value;

        @JsonValue
        public String getValue() {
            return value;
        }

        @JsonCreator
        public static ChangeType fromValue(String value) {
            for (ChangeType changeType : ChangeType.values()) {
                if (changeType.value.equalsIgnoreCase(value)) {
                    return changeType;
                }
            }
            throw new IllegalArgumentException("Unknown enum value: " + value);
        }
    }
}
